/**
 * @(#)ViewAssignments.java
 *
 *
 * @author 
 * @version 1.00 2008/10/17
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSetMetaData;
import java.io.*;

public class ViewAssignments
{
	private static String driver = "org.apache.derby.jdbc.EmbeddedDriver";
	private static String dbName="/DerbyDB/UniLearn";
	private static String connectionURL = "jdbc:derby:" + dbName; 
	private static Connection conn = null;
	private static Statement stmt = null;

    public static void main(String[] args)
    {
    	System.out.println();
    	createConnection();
    	selectAss(args[0]);
    }
    
    private static void createConnection()
    {
    	

		try
		{
    		Class.forName(driver); 
		}
		catch(java.lang.ClassNotFoundException e)
		{
    		e.printStackTrace();
		}

		try {
    	conn = DriverManager.getConnection(connectionURL); 

    //body of code to go here

		}
		 catch (Throwable e)  {   
    		e.printStackTrace();
		}
		finally
		{
//			try
//			{	
//				conn.close();
//			}
//			catch(SQLException e)
//			{
//				e.printStackTrace();
//			}
		}
		
		

    }
    private static void selectAss(String tutorId)
    {
    	try
        {
            stmt = conn.createStatement();
            ResultSet results = stmt.executeQuery("select * from Assignments where TutorId='"+tutorId+"'");
            ResultSetMetaData rsmd = results.getMetaData();
   
                System.out.print("StudentId"+"\t\t"+"Status"+"\t\t"+"Mark");  
            

            System.out.println("\n-------------------------------------------------");

            while(results.next())
            {
            	

                String studentId = results.getString(2);
                String status = results.getString(3);
                
                int mark = results.getInt(4);
                
                String markShow=Integer.toString(mark);
                if(markShow.equals("0"))
                	markShow="Not mark";
                
               
                
                System.out.println(studentId + "\t\t" + status + "\t\t" + markShow);
            }
            results.close();
            stmt.close();
        }
        catch (SQLException sqlExcept)
        {
            sqlExcept.printStackTrace();
        }

    }

    
    
}